import osmnx as ox
import numpy as np
import pandas as pd
import geopandas as gp
import folium
region1 = "Costa Rica"
etiqueta1 = {'amenity':"bank"}
resultado1 = ox.geometries_from_place(query = region1, tags = etiqueta1)
display(resultado1.columns)
Index(['unique_id', 'osmid', 'element_type', 'amenity', 'name', 'geometry',
'addr:city', 'addr:street', 'atm', 'phone', 'name:es', 'nodes', 'brand',
'brand:en', 'brand:es', 'brand:wikidata', 'brand:wikipedia', 'building',
'name:en', 'official_name', 'official_name:en', 'official_name:es',
'short_name', 'source', 'drive_through', 'opening_hours', 'operator',
'website', 'addr:full', 'area', 'alt_name', 'level', 'note',
'addr:postcode', 'building:levels', 'construction', 'fixme',
'designation', 'fee', 'name:de', 'ele', 'addr:housename', 'int_name',
'wheelchair', 'name:it', 'source_1', 'operator:wikidata',
'operator:wikipedia', 'addr:place', 'indoor', 'addr:local', 'parts',
'email', 'buildingpart', 'height', 'phone_1', 'phone_2', 'ways', 'type',
'is_in', 'addr:suburb', 'description', 'addr:housenumber', 'landuse',
'cajero', 'shop', 'building:colour', 'roof:colour', 'air_conditioning',
'amenity_1', 'alt_name:en', 'alt_name:es', 'highway'],
dtype='object')
bancos = resultado1[["name","geometry"]]
bancos = bancos.dropna()
bancosbn = bancos[bancos.name.str.match('^Banco Nacional')]
bancosbcr = bancos[bancos.name.str.match('^Banco de Costa')]
bancosbac = bancos[bancos.name.str.match('^BAC')]
bancosbp = bancos[bancos.name.str.match('^Banco Popular')]
coord1 = pd.concat([bancosbn,bancosbcr,bancosbac,bancosbp])
points1 = coord1[[True if geometry.__class__.__name__ == "Point" else False for geometry in coord1.geometry]]
points1 [["name","geometry"]].head(17)
points1 ['x'] = points1['geometry'].x
points1 ['y'] = points1['geometry'].y
points1 [["name", "x","y"]].head(15)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code) C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\geopandas\geodataframe.py:1322: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy super(GeoDataFrame, self).__setitem__(key, value)
| name | x | y | |
|---|---|---|---|
| 22 | Banco Nacional | -85.841135 | 10.299191 |
| 43 | Banco Nacional | -85.169051 | 10.823264 |
| 55 | Banco Nacional | -85.199647 | 10.672757 |
| 76 | Banco Nacional | -85.418235 | 10.057437 |
| 77 | Banco Nacional | -85.253555 | 9.993134 |
| 88 | Banco Nacional | -85.150928 | 9.628124 |
| 93 | Banco Nacional | -84.716415 | 11.032113 |
| 97 | Banco Nacional | -85.011724 | 10.897287 |
| 103 | Banco Nacional | -85.059176 | 10.728583 |
| 104 | Banco Nacional | -84.896510 | 10.544925 |
| 117 | Banco Nacional | -84.731139 | 10.092833 |
| 123 | Banco Nacional | -84.957120 | 10.280822 |
| 126 | Banco Nacional | -85.114935 | 9.958804 |
| 150 | Banco Nacional | -85.104591 | 9.687205 |
| 159 | Banco Nacional | -84.458890 | 10.466973 |
polygon1= coord1[[True if geometry.__class__.__name__ == "Polygon" else False for geometry in coord1.geometry]]
polygon1[["name","geometry"]].head(15)
polygon1["x"] = polygon1.centroid.x
polygon1["y"] = polygon1.centroid.y
polygon1[["name", "x","y"]].head(15)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code) C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:3: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. This is separate from the ipykernel package so we can avoid doing imports until C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\geopandas\geodataframe.py:1322: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy super(GeoDataFrame, self).__setitem__(key, value) C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:4: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. after removing the cwd from sys.path.
| name | x | y | |
|---|---|---|---|
| 5 | Banco Nacional | -85.629489 | 11.070238 |
| 10 | Banco Nacional | -85.695239 | 10.547340 |
| 12 | Banco Nacional | -85.552203 | 10.445051 |
| 18 | Banco Nacional | -85.781695 | 10.435656 |
| 28 | Banco Nacional | -85.586820 | 10.267494 |
| 30 | Banco Nacional | -85.839514 | 10.296936 |
| 57 | Banco Nacional | -85.440634 | 10.628847 |
| 71 | Banco Nacional | -85.255454 | 10.526186 |
| 79 | Banco Nacional | -85.451839 | 10.145019 |
| 91 | Banco Nacional | -85.528888 | 9.882536 |
| 108 | Banco Nacional | -84.821709 | 10.669061 |
| 111 | Banco Nacional | -85.091362 | 10.427036 |
| 114 | Banco Nacional | -84.968444 | 10.469605 |
| 133 | Banco Nacional | -84.720780 | 9.983245 |
| 137 | Banco Nacional | -84.832643 | 9.979764 |
resultado2 = points1.append(polygon1)
resultado2 = resultado2[["name","x","y","geometry"]]
resultado2[["name", "x","y"]].head(15)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
| name | x | y | |
|---|---|---|---|
| 22 | Banco Nacional | -85.841135 | 10.299191 |
| 43 | Banco Nacional | -85.169051 | 10.823264 |
| 55 | Banco Nacional | -85.199647 | 10.672757 |
| 76 | Banco Nacional | -85.418235 | 10.057437 |
| 77 | Banco Nacional | -85.253555 | 9.993134 |
| 88 | Banco Nacional | -85.150928 | 9.628124 |
| 93 | Banco Nacional | -84.716415 | 11.032113 |
| 97 | Banco Nacional | -85.011724 | 10.897287 |
| 103 | Banco Nacional | -85.059176 | 10.728583 |
| 104 | Banco Nacional | -84.896510 | 10.544925 |
| 117 | Banco Nacional | -84.731139 | 10.092833 |
| 123 | Banco Nacional | -84.957120 | 10.280822 |
| 126 | Banco Nacional | -85.114935 | 9.958804 |
| 150 | Banco Nacional | -85.104591 | 9.687205 |
| 159 | Banco Nacional | -84.458890 | 10.466973 |
m = folium.Map(location=[9.934598, -84.094154], zoom_start = 13)
folium.TileLayer('CartoDB positron').add_to(m)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
<folium.raster_layers.TileLayer at 0x1f003f3dec8>
estilos1 = {"Banco Nacional":{"color":"blue"},"Banco Popular":{"color":"orange"}, "BAC":{"color":"red"}, "Banco de Costa Rica": {"color":"green"}}
for banco in resultado2.itertuples():
if banco.name == 'Banco Nacional':
esti = estilos1["Banco Nacional"]
elif banco.name == 'BAC':
esti = estilos1["BAC"]
elif banco.name == 'Banco Popular':
esti = estilos1["Banco Popular"]
elif banco.name == 'Banco de Costa Rica':
esti = estilos1["Banco de Costa Rica"]
c = folium.Marker(location=[banco.y, banco.x], popup = banco.name,
icon = folium.Icon(color = esti["color"],
icon_color = 'white')).add_to(m)
m
import folium.plugins
n = folium.Map(location=[9.934598, -84.094154], zoom_start = 13)
folium.TileLayer('CartoDB positron').add_to(n)
<folium.raster_layers.TileLayer at 0x1f006355648>
cluster = folium.plugins.MarkerCluster().add_to(n)
for banco in resultado2.itertuples():
if banco.name == 'Banco Nacional':
esti = estilos1["Banco Nacional"]
elif banco.name == 'BAC':
esti = estilos1["BAC"]
elif banco.name == 'Banco Popular':
esti = estilos1["Banco Popular"]
elif banco.name == 'Banco de Costa Rica':
esti = estilos1["Banco de Costa Rica"]
d = folium.Marker(location=[banco.y, banco.x], popup = banco.name,
icon = folium.Icon(color = esti["color"],
icon_color = 'white')).add_to(cluster)
n
Para este ejercicio se emplea la plataforma Open Street Map en python para analizar a traves de un mapa interactivo. Las variables iniciales del resultado indican que los bancos en general desde una perspectiva optica estan conglomerados en zonas urbanas de Costa Rica. Estos bancos se concentran especialmente en la GAM. Debe denotarse que los cuatro bancos analizados representan cuatro de los bancos mas grandes de Costa Rica. Se puede notar que los bancos publicos estan mas dispersos a traves del pais encontrandose inclusive en zonas alejadas fronterizas, aunque el BAC esta tambien presente en zonas alejadas parece ser mas ciudades intermedias. El resultado muestra a San Jose como un gran cluster bancario en Costa Rica llgando a concentrar segun las tablas mas de la cuarta parte de las sucursales.
import geopandas as gp
import os
pasada = os.getcwd()
os.chdir("C:/Users/rzamoram/OneDrive - Intel Corporation/Documents/Machine Learning/Visualizacion de Datos en Python/Semana 3")
print(os.getcwd())
datos_covid = pd.read_excel(io = "base-de-datos-IPS-cantonal.xlsx", sheet_name= "Datos")
datos_covid.head(15)
C:\Users\rzamoram\OneDrive - Intel Corporation\Documents\Machine Learning\Visualizacion de Datos en Python\Semana 3
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code) C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\openpyxl\worksheet\_reader.py:312: UserWarning: Unknown extension is not supported and will be removed warn(msg)
| cve | canton | Nutrición y Asistencia Médica Básica | Agua y Saneamiento | Vivienda | Seguridad Personal | Acceso a Conocimientos Básicos | Acceso a Información y Comunicaciones | Salud y Bienestar | Sustentabilidad del Ecosistema | ... | Rendición de cuentas | Acceso a la cultura y recreación | Inclusión al adulto mayor | Inclusión a población con discapacidad | Inclusión población indígena | Inclusión de migrantes | Inclusión de hogares con jefatura femenina | Población con educación superior | Escolaridad promedio de las mujeres | Población con educación técnica | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 101 | SAN JOSE | 82.987394 | 98.665964 | 63.891581 | 43.713222 | 84.284809 | 73.758822 | 64.570213 | 39.810430 | ... | 95.3 | 20.552 | 5.252235 | 7.709731 | 7.919016 | 25.562775 | 36.874519 | 29.469448 | 9.733187 | 4.329589 |
| 1 | 102 | ESCAZU | 85.931253 | 98.121264 | 86.023111 | 52.939193 | 88.650664 | 77.359311 | 67.819220 | 64.554111 | ... | 90.0 | 15.573 | 6.169883 | 6.741573 | 6.495726 | 10.226506 | 29.850746 | 40.279616 | 10.583268 | 4.197981 |
| 2 | 103 | DESAMPARADOS | 88.541844 | 94.700064 | 80.789600 | 58.999818 | 88.804140 | 70.986816 | 68.089101 | 48.467391 | ... | 33.3 | 3.071 | 5.102137 | 8.366314 | 9.358289 | 18.081342 | 31.065089 | 21.696907 | 9.038890 | 5.288635 |
| 3 | 104 | PURISCAL | 90.993459 | 89.766092 | 90.227325 | 86.085942 | 84.829898 | 58.456934 | 76.552294 | 65.577701 | ... | 97.7 | 5.454 | 8.805477 | 6.519700 | 8.341232 | 27.045770 | 17.241379 | 20.662035 | 8.512712 | 7.423228 |
| 4 | 105 | TARRAZU | 91.495155 | 96.414943 | 88.021404 | 65.438845 | 77.763379 | 55.222121 | 77.395928 | 71.499005 | ... | 81.0 | 8.600 | 4.359313 | 10.572391 | 33.012821 | 25.316456 | 11.111111 | 12.510132 | 7.431191 | 3.440599 |
| 5 | 106 | ASERRI | 86.784734 | 96.168135 | 80.561890 | 66.061311 | 81.685512 | 64.817405 | 71.933404 | 53.966119 | ... | 58.6 | 2.246 | 8.748086 | 10.624700 | 15.035800 | 19.402460 | 32.380952 | 15.951560 | 8.207674 | 4.264233 |
| 6 | 107 | MORA | 94.646702 | 97.904214 | 89.352456 | 79.862203 | 88.759700 | 65.509299 | 76.397497 | 57.845085 | ... | 100.0 | 5.705 | 7.371255 | 7.009694 | 7.415107 | 12.348285 | 33.333333 | 25.396500 | 9.231101 | 5.292150 |
| 7 | 108 | GOICOECHEA | 79.610864 | 97.117050 | 81.540361 | 59.889931 | 84.789348 | 75.439587 | 72.450279 | 54.076321 | ... | 95.3 | 9.211 | 3.743543 | 7.386839 | 7.528409 | 18.536721 | 44.827586 | 28.628814 | 9.704617 | 4.284503 |
| 8 | 109 | SANTA ANA | 90.396596 | 97.623372 | 85.832592 | 70.975364 | 86.128275 | 76.802068 | 77.286935 | 53.389931 | ... | 96.3 | 13.436 | 4.861970 | 6.687831 | 7.293355 | 10.380864 | 35.714286 | 37.245247 | 10.364677 | 4.317240 |
| 9 | 110 | ALAJUELITA | 93.168844 | 98.544700 | 46.213978 | 54.301052 | 72.204454 | 66.581548 | 74.415128 | 52.536875 | ... | 86.7 | 0.387 | 9.020097 | 13.531239 | 13.857678 | 26.518178 | 37.401575 | 13.850704 | 8.161253 | 3.350159 |
| 10 | 111 | VASQUEZ DE CORONADO | 82.283449 | 91.838378 | 88.568240 | 68.306229 | 83.726808 | 76.577199 | 72.162253 | 62.587511 | ... | 53.3 | 10.250 | 3.872730 | 6.229508 | 4.628331 | 7.857143 | 34.285714 | 31.075820 | 9.933610 | 4.422015 |
| 11 | 112 | ACOSTA | 93.875730 | 97.293550 | 86.457535 | 96.328282 | 84.774440 | 50.580246 | 77.384992 | 68.824344 | ... | 40.6 | 2.474 | 11.769912 | 8.275862 | 10.714286 | 15.352697 | 23.529412 | 11.857351 | 7.611447 | 11.082159 |
| 12 | 113 | TIBAS | 94.036383 | 99.234036 | 74.550356 | 41.264714 | 75.808156 | 74.929249 | 57.225469 | 51.469446 | ... | 81.7 | 12.029 | 3.810577 | 5.629991 | 4.623116 | 23.195649 | 35.742972 | 34.699030 | 10.188252 | 4.610979 |
| 13 | 114 | MORAVIA | 96.160704 | 99.021264 | 91.392283 | 70.452464 | 90.366621 | 79.269724 | 73.507914 | 61.066812 | ... | 94.3 | 13.352 | 3.259098 | 5.356545 | 7.284768 | 8.231972 | 16.129032 | 40.004579 | 10.807282 | 4.478757 |
| 14 | 115 | MONTES DE OCA | 94.328260 | 90.410728 | 93.709855 | 20.158451 | 74.780648 | 82.424025 | 69.421412 | 57.335312 | ... | 75.3 | 28.291 | 2.073171 | 3.572090 | 3.030303 | 8.791028 | 23.809524 | 51.987624 | 11.828741 | 4.365419 |
15 rows × 64 columns
datos_covid = pd.melt(datos_covid,
id_vars = ['cve',"canton"],
var_name = 'oportunidades',
value_name = 'ips')
datos_covid.head(10)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code) C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\IPython\core\interactiveshell.py:3437: FutureWarning: This dataframe has a column name that matches the 'value_name' column name of the resulting Dataframe. In the future this will raise an error, please set the 'value_name' parameter of DataFrame.melt to a unique name. exec(code_obj, self.user_global_ns, self.user_ns)
| cve | canton | oportunidades | ips | |
|---|---|---|---|---|
| 0 | 101 | SAN JOSE | Nutrición y Asistencia Médica Básica | 82.987394 |
| 1 | 102 | ESCAZU | Nutrición y Asistencia Médica Básica | 85.931253 |
| 2 | 103 | DESAMPARADOS | Nutrición y Asistencia Médica Básica | 88.541844 |
| 3 | 104 | PURISCAL | Nutrición y Asistencia Médica Básica | 90.993459 |
| 4 | 105 | TARRAZU | Nutrición y Asistencia Médica Básica | 91.495155 |
| 5 | 106 | ASERRI | Nutrición y Asistencia Médica Básica | 86.784734 |
| 6 | 107 | MORA | Nutrición y Asistencia Médica Básica | 94.646702 |
| 7 | 108 | GOICOECHEA | Nutrición y Asistencia Médica Básica | 79.610864 |
| 8 | 109 | SANTA ANA | Nutrición y Asistencia Médica Básica | 90.396596 |
| 9 | 110 | ALAJUELITA | Nutrición y Asistencia Médica Básica | 93.168844 |
cantones = gp.read_file("geo_data/cantones/cantones.shp")
cantones.head()
#san_jose = cantones[cantones.provincia == "Cartago"]
#san_jose.head(5)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
| provincia | canton | poblacion | area_k2 | geometry | |
|---|---|---|---|---|---|
| 0 | Puntarenas | Corredores | 51291.0 | 623.723527 | POLYGON ((-82.90137 8.72708, -82.90033 8.72265... |
| 1 | Puntarenas | Golfito | 44572.0 | 1750.056183 | MULTIPOLYGON (((-83.46660 8.68827, -83.46669 8... |
| 2 | Puntarenas | Coto Brus | 44176.0 | 944.175405 | POLYGON ((-82.96647 9.09421, -82.96337 9.09420... |
| 3 | Puntarenas | Osa | 30818.0 | 1922.774483 | POLYGON ((-83.83946 9.25534, -83.83642 9.25533... |
| 4 | Puntarenas | Buenos Aires | 52126.0 | 2382.972927 | POLYGON ((-83.32101 9.38409, -83.31462 9.38327... |
cantones = gp.read_file("geo_data/cantones/cantones.shp")
cantones = cantones.set_index('canton')
cantones.head(10)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
| provincia | poblacion | area_k2 | geometry | |
|---|---|---|---|---|
| canton | ||||
| Corredores | Puntarenas | 51291.0 | 623.723527 | POLYGON ((-82.90137 8.72708, -82.90033 8.72265... |
| Golfito | Puntarenas | 44572.0 | 1750.056183 | MULTIPOLYGON (((-83.46660 8.68827, -83.46669 8... |
| Coto Brus | Puntarenas | 44176.0 | 944.175405 | POLYGON ((-82.96647 9.09421, -82.96337 9.09420... |
| Osa | Puntarenas | 30818.0 | 1922.774483 | POLYGON ((-83.83946 9.25534, -83.83642 9.25533... |
| Buenos Aires | Puntarenas | 52126.0 | 2382.972927 | POLYGON ((-83.32101 9.38409, -83.31462 9.38327... |
| Pérez Zeledón | San José | 142789.0 | 1901.393446 | POLYGON ((-83.77329 9.59825, -83.77217 9.59826... |
| Quepos | Puntarenas | 32121.0 | 559.010331 | POLYGON ((-84.13572 9.57168, -84.13337 9.57091... |
| Talamanca | Limón | 41518.0 | 2814.658267 | POLYGON ((-82.89452 9.76752, -82.89216 9.76713... |
| Parrita | Puntarenas | 19457.0 | 479.629981 | POLYGON ((-84.30298 9.64969, -84.30067 9.64754... |
| Tarrazú | San José | 18264.0 | 290.111618 | POLYGON ((-83.98178 9.71802, -83.97882 9.71819... |
import re
def eliminar_tildes(texto):
texto = re.sub('á','a', texto)
texto = re.sub('é','e', texto)
texto = re.sub('í','i', texto)
texto = re.sub('ó','o', texto)
texto = re.sub('ú','u', texto)
texto = re.sub('ñ','n', texto)
return texto.upper()
def arreglar_cantones(texto):
texto = eliminar_tildes(texto)
texto = re.sub('LEON CORTES CASTRO','LEON CORTES', texto)
texto = re.sub('VAZQUEZ DE CORONADO','VASQUEZ DE CORONADO', texto)
texto = re.sub('VALVERDE VEGA','SARCHI', texto)
return texto
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
cantones.index = [arreglar_cantones(x) for x in cantones.index]
cantones.head()
| provincia | poblacion | area_k2 | geometry | |
|---|---|---|---|---|
| CORREDORES | Puntarenas | 51291.0 | 623.723527 | POLYGON ((-82.90137 8.72708, -82.90033 8.72265... |
| GOLFITO | Puntarenas | 44572.0 | 1750.056183 | MULTIPOLYGON (((-83.46660 8.68827, -83.46669 8... |
| COTO BRUS | Puntarenas | 44176.0 | 944.175405 | POLYGON ((-82.96647 9.09421, -82.96337 9.09420... |
| OSA | Puntarenas | 30818.0 | 1922.774483 | POLYGON ((-83.83946 9.25534, -83.83642 9.25533... |
| BUENOS AIRES | Puntarenas | 52126.0 | 2382.972927 | POLYGON ((-83.32101 9.38409, -83.31462 9.38327... |
datos_covid.index = [arreglar_cantones(x) for x in datos_covid.canton]
datos_covid.head()
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
| cve | canton | oportunidades | ips | |
|---|---|---|---|---|
| SAN JOSE | 101 | SAN JOSE | Nutrición y Asistencia Médica Básica | 82.987394 |
| ESCAZU | 102 | ESCAZU | Nutrición y Asistencia Médica Básica | 85.931253 |
| DESAMPARADOS | 103 | DESAMPARADOS | Nutrición y Asistencia Médica Básica | 88.541844 |
| PURISCAL | 104 | PURISCAL | Nutrición y Asistencia Médica Básica | 90.993459 |
| TARRAZU | 105 | TARRAZU | Nutrición y Asistencia Médica Básica | 91.495155 |
set(cantones.index) - set(datos_covid.index)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
{'CANAS', 'RIO CUARTO'}
df = cantones.merge(delitos_mes_canton, left_on = "canton", right_index=True)
df.head(15)
| provincia | canton | poblacion | area_k2 | geometry | indice | |
|---|---|---|---|---|---|---|
| 0 | Puntarenas | CORREDORES | 51291.0 | 623.723527 | POLYGON ((-82.90137 8.72708, -82.90033 8.72265... | 1 |
| 1 | Puntarenas | GOLFITO | 44572.0 | 1750.056183 | MULTIPOLYGON (((-83.46660 8.68827, -83.46669 8... | 1 |
| 2 | Puntarenas | COTO BRUS | 44176.0 | 944.175405 | POLYGON ((-82.96647 9.09421, -82.96337 9.09420... | 1 |
| 3 | Puntarenas | OSA | 30818.0 | 1922.774483 | POLYGON ((-83.83946 9.25534, -83.83642 9.25533... | 1 |
| 4 | Puntarenas | BUENOS AIRES | 52126.0 | 2382.972927 | POLYGON ((-83.32101 9.38409, -83.31462 9.38327... | 1 |
| 5 | San José | PEREZ ZELEDON | 142789.0 | 1901.393446 | POLYGON ((-83.77329 9.59825, -83.77217 9.59826... | 1 |
| 6 | Puntarenas | QUEPOS | 32121.0 | 559.010331 | POLYGON ((-84.13572 9.57168, -84.13337 9.57091... | 1 |
| 7 | Limón | TALAMANCA | 41518.0 | 2814.658267 | POLYGON ((-82.89452 9.76752, -82.89216 9.76713... | 1 |
| 8 | Puntarenas | PARRITA | 19457.0 | 479.629981 | POLYGON ((-84.30298 9.64969, -84.30067 9.64754... | 1 |
| 9 | San José | TARRAZU | 18264.0 | 290.111618 | POLYGON ((-83.98178 9.71802, -83.97882 9.71819... | 1 |
| 10 | San José | DOTA | 7846.0 | 405.833655 | POLYGON ((-83.98595 9.73927, -83.98254 9.73711... | 1 |
| 11 | Puntarenas | GARABITO | 24737.0 | 315.381452 | POLYGON ((-84.67583 9.87729, -84.67448 9.87743... | 1 |
| 12 | San José | LEON CORTES CASTRO | 13493.0 | 121.938260 | POLYGON ((-84.09415 9.74942, -84.09264 9.74917... | 1 |
| 13 | San José | PURISCAL | 37345.0 | 554.985169 | POLYGON ((-84.40184 9.90958, -84.40088 9.90939... | 1 |
| 14 | San José | ASERRI | 62477.0 | 168.425499 | POLYGON ((-84.08014 9.87557, -84.07916 9.87509... | 1 |
df = cantones.merge(datos_covid,how = "left",
left_index = True,
right_index = True)
df.head(15)
| provincia | poblacion | area_k2 | geometry | cve | canton | oportunidades | ips | |
|---|---|---|---|---|---|---|---|---|
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Nutrición y Asistencia Médica Básica | 85.280540 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Agua y Saneamiento | 95.038378 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Vivienda | 69.104107 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Seguridad Personal | 87.244399 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Acceso a Conocimientos Básicos | 83.601755 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Acceso a Información y Comunicaciones | 50.593854 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Salud y Bienestar | 70.678446 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Sustentabilidad del Ecosistema | 56.886927 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Derechos Personales | 76.330000 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Libertad Personal y de Elección | 78.121495 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Tolerancia e Inclusión | 78.881617 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Acceso a Educación Superior | 37.934010 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Necesidades Humanas Básicas | 84.166856 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Fundamentos del Bienestar | 65.440245 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | oportunidades | 67.816781 |
df.ips
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
ABANGARES 85.280540
ABANGARES 95.038378
ABANGARES 69.104107
ABANGARES 87.244399
ABANGARES 83.601755
...
ZARCERO 26.500000
ZARCERO 7.142857
ZARCERO 17.326789
ZARCERO 8.399566
ZARCERO 2.007853
Name: ips, Length: 4962, dtype: float64
x = df.centroid.x.mean()
print(x)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:1: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. """Entry point for launching an IPython kernel.
-84.22688272122
y = df.centroid.y.mean()
print(y)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:1: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. """Entry point for launching an IPython kernel.
9.955756377280855
import folium
x = df.centroid.x.mean()
y = df.centroid.y.mean()
m = folium.Map(location=[y, x], zoom_start = 9, tiles = None)
folium.TileLayer('CartoDB positron',control=False).add_to(m)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:3: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. This is separate from the ipykernel package so we can avoid doing imports until C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:4: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. after removing the cwd from sys.path.
<folium.raster_layers.TileLayer at 0x1f008785188>
cantones = gp.read_file("geo_data/cantones/cantones.shp")
cantones.head()
cantones = cantones[cantones.provincia == "Cartago"]
cantones.head(5)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
| provincia | canton | poblacion | area_k2 | geometry | |
|---|---|---|---|---|---|
| 18 | Cartago | El Guarco | 45548.0 | 171.573039 | POLYGON ((-83.93649 9.85420, -83.92932 9.85254... |
| 19 | Cartago | Cartago | 161727.0 | 278.997036 | POLYGON ((-83.86737 9.97095, -83.86892 9.96971... |
| 21 | Cartago | Paraíso | 62007.0 | 477.139035 | POLYGON ((-83.77791 9.89517, -83.77752 9.89362... |
| 22 | Cartago | Jiménez | 16255.0 | 250.075984 | POLYGON ((-83.76414 9.94766, -83.75970 9.94653... |
| 23 | Cartago | Turrialba | 73616.0 | 1589.335834 | POLYGON ((-83.81609 10.08361, -83.72326 10.039... |
cantones = cantones.set_index('canton')
cantones.head(10)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
| provincia | poblacion | area_k2 | geometry | |
|---|---|---|---|---|
| canton | ||||
| El Guarco | Cartago | 45548.0 | 171.573039 | POLYGON ((-83.93649 9.85420, -83.92932 9.85254... |
| Cartago | Cartago | 161727.0 | 278.997036 | POLYGON ((-83.86737 9.97095, -83.86892 9.96971... |
| Paraíso | Cartago | 62007.0 | 477.139035 | POLYGON ((-83.77791 9.89517, -83.77752 9.89362... |
| Jiménez | Cartago | 16255.0 | 250.075984 | POLYGON ((-83.76414 9.94766, -83.75970 9.94653... |
| Turrialba | Cartago | 73616.0 | 1589.335834 | POLYGON ((-83.81609 10.08361, -83.72326 10.039... |
| Oreamuno | Cartago | 49229.0 | 202.971856 | POLYGON ((-83.94739 10.14751, -83.81563 10.083... |
| La Unión | Cartago | 110194.0 | 44.184626 | POLYGON ((-84.03564 9.88764, -84.03731 9.88878... |
| Alvarado | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... |
cantones.index = [arreglar_cantones(x) for x in cantones.index]
cantones.head()
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
| provincia | poblacion | area_k2 | geometry | |
|---|---|---|---|---|
| EL GUARCO | Cartago | 45548.0 | 171.573039 | POLYGON ((-83.93649 9.85420, -83.92932 9.85254... |
| CARTAGO | Cartago | 161727.0 | 278.997036 | POLYGON ((-83.86737 9.97095, -83.86892 9.96971... |
| PARAISO | Cartago | 62007.0 | 477.139035 | POLYGON ((-83.77791 9.89517, -83.77752 9.89362... |
| JIMENEZ | Cartago | 16255.0 | 250.075984 | POLYGON ((-83.76414 9.94766, -83.75970 9.94653... |
| TURRIALBA | Cartago | 73616.0 | 1589.335834 | POLYGON ((-83.81609 10.08361, -83.72326 10.039... |
datos_covid.index = [arreglar_cantones(x) for x in datos_covid.canton]
datos_covid.head()
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
| cve | canton | oportunidades | ips | |
|---|---|---|---|---|
| SAN JOSE | 101 | SAN JOSE | Nutrición y Asistencia Médica Básica | 82.987394 |
| ESCAZU | 102 | ESCAZU | Nutrición y Asistencia Médica Básica | 85.931253 |
| DESAMPARADOS | 103 | DESAMPARADOS | Nutrición y Asistencia Médica Básica | 88.541844 |
| PURISCAL | 104 | PURISCAL | Nutrición y Asistencia Médica Básica | 90.993459 |
| TARRAZU | 105 | TARRAZU | Nutrición y Asistencia Médica Básica | 91.495155 |
set(cantones.index) - set(datos_covid.index)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
set()
df = cantones.merge(datos_covid,how = "left",
left_index = True,
right_index = True)
df.head(15)
| provincia | poblacion | area_k2 | geometry | cve | canton | oportunidades | ips | |
|---|---|---|---|---|---|---|---|---|
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Nutrición y Asistencia Médica Básica | 92.760577 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Agua y Saneamiento | 97.978736 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Vivienda | 89.356684 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Seguridad Personal | 69.972781 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Acceso a Conocimientos Básicos | 88.816013 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Acceso a Información y Comunicaciones | 54.923713 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Salud y Bienestar | 80.897354 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Sustentabilidad del Ecosistema | 67.803337 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Derechos Personales | 79.770000 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Libertad Personal y de Elección | 79.237891 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Tolerancia e Inclusión | 79.774300 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Acceso a Educación Superior | 36.487360 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Necesidades Humanas Básicas | 87.517195 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Fundamentos del Bienestar | 73.110104 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | oportunidades | 68.817388 |
x = df.centroid.x.mean()
print(x)
-83.81587522794443
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code) C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:1: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. """Entry point for launching an IPython kernel.
y = df.centroid.y.mean()
print(y)
9.845582134363136
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:1: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. """Entry point for launching an IPython kernel.
import folium
x = df.centroid.x.mean()
y = df.centroid.y.mean()
m = folium.Map(location=[y, x], zoom_start = 9, tiles = None)
folium.TileLayer('CartoDB positron',control=False).add_to(m)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:3: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. This is separate from the ipykernel package so we can avoid doing imports until C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:4: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. after removing the cwd from sys.path.
<folium.raster_layers.TileLayer at 0x1f00adeba08>
choropleth = folium.Choropleth(
geo_data = df,
data = df,
columns = ["canton","ips"],
key_on = "feature.properties.canton",
fill_color = 'OrRd',
highlight = True).add_to(m)
m
import geopandas as gp
import os
pasada = os.getcwd()
os.chdir("C:/Users/rzamoram/OneDrive - Intel Corporation/Documents/Machine Learning/Visualizacion de Datos en Python/Semana 3")
print(os.getcwd())
datos_covid = pd.read_excel(io = "base-de-datos-IPS-cantonal.xlsx", sheet_name= "Datos")
datos_covid.head(15)
C:\Users\rzamoram\OneDrive - Intel Corporation\Documents\Machine Learning\Visualizacion de Datos en Python\Semana 3
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code) C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\openpyxl\worksheet\_reader.py:312: UserWarning: Unknown extension is not supported and will be removed warn(msg)
| cve | canton | Nutrición y Asistencia Médica Básica | Agua y Saneamiento | Vivienda | Seguridad Personal | Acceso a Conocimientos Básicos | Acceso a Información y Comunicaciones | Salud y Bienestar | Sustentabilidad del Ecosistema | ... | Rendición de cuentas | Acceso a la cultura y recreación | Inclusión al adulto mayor | Inclusión a población con discapacidad | Inclusión población indígena | Inclusión de migrantes | Inclusión de hogares con jefatura femenina | Población con educación superior | Escolaridad promedio de las mujeres | Población con educación técnica | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 101 | SAN JOSE | 82.987394 | 98.665964 | 63.891581 | 43.713222 | 84.284809 | 73.758822 | 64.570213 | 39.810430 | ... | 95.3 | 20.552 | 5.252235 | 7.709731 | 7.919016 | 25.562775 | 36.874519 | 29.469448 | 9.733187 | 4.329589 |
| 1 | 102 | ESCAZU | 85.931253 | 98.121264 | 86.023111 | 52.939193 | 88.650664 | 77.359311 | 67.819220 | 64.554111 | ... | 90.0 | 15.573 | 6.169883 | 6.741573 | 6.495726 | 10.226506 | 29.850746 | 40.279616 | 10.583268 | 4.197981 |
| 2 | 103 | DESAMPARADOS | 88.541844 | 94.700064 | 80.789600 | 58.999818 | 88.804140 | 70.986816 | 68.089101 | 48.467391 | ... | 33.3 | 3.071 | 5.102137 | 8.366314 | 9.358289 | 18.081342 | 31.065089 | 21.696907 | 9.038890 | 5.288635 |
| 3 | 104 | PURISCAL | 90.993459 | 89.766092 | 90.227325 | 86.085942 | 84.829898 | 58.456934 | 76.552294 | 65.577701 | ... | 97.7 | 5.454 | 8.805477 | 6.519700 | 8.341232 | 27.045770 | 17.241379 | 20.662035 | 8.512712 | 7.423228 |
| 4 | 105 | TARRAZU | 91.495155 | 96.414943 | 88.021404 | 65.438845 | 77.763379 | 55.222121 | 77.395928 | 71.499005 | ... | 81.0 | 8.600 | 4.359313 | 10.572391 | 33.012821 | 25.316456 | 11.111111 | 12.510132 | 7.431191 | 3.440599 |
| 5 | 106 | ASERRI | 86.784734 | 96.168135 | 80.561890 | 66.061311 | 81.685512 | 64.817405 | 71.933404 | 53.966119 | ... | 58.6 | 2.246 | 8.748086 | 10.624700 | 15.035800 | 19.402460 | 32.380952 | 15.951560 | 8.207674 | 4.264233 |
| 6 | 107 | MORA | 94.646702 | 97.904214 | 89.352456 | 79.862203 | 88.759700 | 65.509299 | 76.397497 | 57.845085 | ... | 100.0 | 5.705 | 7.371255 | 7.009694 | 7.415107 | 12.348285 | 33.333333 | 25.396500 | 9.231101 | 5.292150 |
| 7 | 108 | GOICOECHEA | 79.610864 | 97.117050 | 81.540361 | 59.889931 | 84.789348 | 75.439587 | 72.450279 | 54.076321 | ... | 95.3 | 9.211 | 3.743543 | 7.386839 | 7.528409 | 18.536721 | 44.827586 | 28.628814 | 9.704617 | 4.284503 |
| 8 | 109 | SANTA ANA | 90.396596 | 97.623372 | 85.832592 | 70.975364 | 86.128275 | 76.802068 | 77.286935 | 53.389931 | ... | 96.3 | 13.436 | 4.861970 | 6.687831 | 7.293355 | 10.380864 | 35.714286 | 37.245247 | 10.364677 | 4.317240 |
| 9 | 110 | ALAJUELITA | 93.168844 | 98.544700 | 46.213978 | 54.301052 | 72.204454 | 66.581548 | 74.415128 | 52.536875 | ... | 86.7 | 0.387 | 9.020097 | 13.531239 | 13.857678 | 26.518178 | 37.401575 | 13.850704 | 8.161253 | 3.350159 |
| 10 | 111 | VASQUEZ DE CORONADO | 82.283449 | 91.838378 | 88.568240 | 68.306229 | 83.726808 | 76.577199 | 72.162253 | 62.587511 | ... | 53.3 | 10.250 | 3.872730 | 6.229508 | 4.628331 | 7.857143 | 34.285714 | 31.075820 | 9.933610 | 4.422015 |
| 11 | 112 | ACOSTA | 93.875730 | 97.293550 | 86.457535 | 96.328282 | 84.774440 | 50.580246 | 77.384992 | 68.824344 | ... | 40.6 | 2.474 | 11.769912 | 8.275862 | 10.714286 | 15.352697 | 23.529412 | 11.857351 | 7.611447 | 11.082159 |
| 12 | 113 | TIBAS | 94.036383 | 99.234036 | 74.550356 | 41.264714 | 75.808156 | 74.929249 | 57.225469 | 51.469446 | ... | 81.7 | 12.029 | 3.810577 | 5.629991 | 4.623116 | 23.195649 | 35.742972 | 34.699030 | 10.188252 | 4.610979 |
| 13 | 114 | MORAVIA | 96.160704 | 99.021264 | 91.392283 | 70.452464 | 90.366621 | 79.269724 | 73.507914 | 61.066812 | ... | 94.3 | 13.352 | 3.259098 | 5.356545 | 7.284768 | 8.231972 | 16.129032 | 40.004579 | 10.807282 | 4.478757 |
| 14 | 115 | MONTES DE OCA | 94.328260 | 90.410728 | 93.709855 | 20.158451 | 74.780648 | 82.424025 | 69.421412 | 57.335312 | ... | 75.3 | 28.291 | 2.073171 | 3.572090 | 3.030303 | 8.791028 | 23.809524 | 51.987624 | 11.828741 | 4.365419 |
15 rows × 64 columns
datos_covid = pd.melt(datos_covid,
id_vars = ['cve',"canton"],
var_name = 'oportunidades',
value_name = 'Vivienda')
datos_covid.head(10)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code) C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\IPython\core\interactiveshell.py:3437: FutureWarning: This dataframe has a column name that matches the 'value_name' column name of the resulting Dataframe. In the future this will raise an error, please set the 'value_name' parameter of DataFrame.melt to a unique name. exec(code_obj, self.user_global_ns, self.user_ns)
| cve | canton | oportunidades | Vivienda | |
|---|---|---|---|---|
| 0 | 101 | SAN JOSE | Nutrición y Asistencia Médica Básica | 82.987394 |
| 1 | 102 | ESCAZU | Nutrición y Asistencia Médica Básica | 85.931253 |
| 2 | 103 | DESAMPARADOS | Nutrición y Asistencia Médica Básica | 88.541844 |
| 3 | 104 | PURISCAL | Nutrición y Asistencia Médica Básica | 90.993459 |
| 4 | 105 | TARRAZU | Nutrición y Asistencia Médica Básica | 91.495155 |
| 5 | 106 | ASERRI | Nutrición y Asistencia Médica Básica | 86.784734 |
| 6 | 107 | MORA | Nutrición y Asistencia Médica Básica | 94.646702 |
| 7 | 108 | GOICOECHEA | Nutrición y Asistencia Médica Básica | 79.610864 |
| 8 | 109 | SANTA ANA | Nutrición y Asistencia Médica Básica | 90.396596 |
| 9 | 110 | ALAJUELITA | Nutrición y Asistencia Médica Básica | 93.168844 |
cantones = gp.read_file("geo_data/cantones/cantones.shp")
cantones.head()
#san_jose = cantones[cantones.provincia == "Cartago"]
#san_jose.head(5)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
| provincia | canton | poblacion | area_k2 | geometry | |
|---|---|---|---|---|---|
| 0 | Puntarenas | Corredores | 51291.0 | 623.723527 | POLYGON ((-82.90137 8.72708, -82.90033 8.72265... |
| 1 | Puntarenas | Golfito | 44572.0 | 1750.056183 | MULTIPOLYGON (((-83.46660 8.68827, -83.46669 8... |
| 2 | Puntarenas | Coto Brus | 44176.0 | 944.175405 | POLYGON ((-82.96647 9.09421, -82.96337 9.09420... |
| 3 | Puntarenas | Osa | 30818.0 | 1922.774483 | POLYGON ((-83.83946 9.25534, -83.83642 9.25533... |
| 4 | Puntarenas | Buenos Aires | 52126.0 | 2382.972927 | POLYGON ((-83.32101 9.38409, -83.31462 9.38327... |
cantones = gp.read_file("geo_data/cantones/cantones.shp")
cantones.head()
cantones = cantones[cantones.provincia == "Cartago"]
cantones.head(5)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
| provincia | canton | poblacion | area_k2 | geometry | |
|---|---|---|---|---|---|
| 18 | Cartago | El Guarco | 45548.0 | 171.573039 | POLYGON ((-83.93649 9.85420, -83.92932 9.85254... |
| 19 | Cartago | Cartago | 161727.0 | 278.997036 | POLYGON ((-83.86737 9.97095, -83.86892 9.96971... |
| 21 | Cartago | Paraíso | 62007.0 | 477.139035 | POLYGON ((-83.77791 9.89517, -83.77752 9.89362... |
| 22 | Cartago | Jiménez | 16255.0 | 250.075984 | POLYGON ((-83.76414 9.94766, -83.75970 9.94653... |
| 23 | Cartago | Turrialba | 73616.0 | 1589.335834 | POLYGON ((-83.81609 10.08361, -83.72326 10.039... |
cantones = gp.read_file("geo_data/cantones/cantones.shp")
cantones = cantones.set_index('canton')
cantones.head(10)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
| provincia | poblacion | area_k2 | geometry | |
|---|---|---|---|---|
| canton | ||||
| Corredores | Puntarenas | 51291.0 | 623.723527 | POLYGON ((-82.90137 8.72708, -82.90033 8.72265... |
| Golfito | Puntarenas | 44572.0 | 1750.056183 | MULTIPOLYGON (((-83.46660 8.68827, -83.46669 8... |
| Coto Brus | Puntarenas | 44176.0 | 944.175405 | POLYGON ((-82.96647 9.09421, -82.96337 9.09420... |
| Osa | Puntarenas | 30818.0 | 1922.774483 | POLYGON ((-83.83946 9.25534, -83.83642 9.25533... |
| Buenos Aires | Puntarenas | 52126.0 | 2382.972927 | POLYGON ((-83.32101 9.38409, -83.31462 9.38327... |
| Pérez Zeledón | San José | 142789.0 | 1901.393446 | POLYGON ((-83.77329 9.59825, -83.77217 9.59826... |
| Quepos | Puntarenas | 32121.0 | 559.010331 | POLYGON ((-84.13572 9.57168, -84.13337 9.57091... |
| Talamanca | Limón | 41518.0 | 2814.658267 | POLYGON ((-82.89452 9.76752, -82.89216 9.76713... |
| Parrita | Puntarenas | 19457.0 | 479.629981 | POLYGON ((-84.30298 9.64969, -84.30067 9.64754... |
| Tarrazú | San José | 18264.0 | 290.111618 | POLYGON ((-83.98178 9.71802, -83.97882 9.71819... |
cantones.index = [arreglar_cantones(x) for x in cantones.index]
cantones.head()
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
| provincia | poblacion | area_k2 | geometry | |
|---|---|---|---|---|
| CORREDORES | Puntarenas | 51291.0 | 623.723527 | POLYGON ((-82.90137 8.72708, -82.90033 8.72265... |
| GOLFITO | Puntarenas | 44572.0 | 1750.056183 | MULTIPOLYGON (((-83.46660 8.68827, -83.46669 8... |
| COTO BRUS | Puntarenas | 44176.0 | 944.175405 | POLYGON ((-82.96647 9.09421, -82.96337 9.09420... |
| OSA | Puntarenas | 30818.0 | 1922.774483 | POLYGON ((-83.83946 9.25534, -83.83642 9.25533... |
| BUENOS AIRES | Puntarenas | 52126.0 | 2382.972927 | POLYGON ((-83.32101 9.38409, -83.31462 9.38327... |
datos_covid.index = [arreglar_cantones(x) for x in datos_covid.canton]
datos_covid.head()
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
| cve | canton | oportunidades | Vivienda | |
|---|---|---|---|---|
| SAN JOSE | 101 | SAN JOSE | Nutrición y Asistencia Médica Básica | 82.987394 |
| ESCAZU | 102 | ESCAZU | Nutrición y Asistencia Médica Básica | 85.931253 |
| DESAMPARADOS | 103 | DESAMPARADOS | Nutrición y Asistencia Médica Básica | 88.541844 |
| PURISCAL | 104 | PURISCAL | Nutrición y Asistencia Médica Básica | 90.993459 |
| TARRAZU | 105 | TARRAZU | Nutrición y Asistencia Médica Básica | 91.495155 |
set(cantones.index) - set(datos_covid.index)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
{'CANAS', 'RIO CUARTO'}
df = cantones.merge(datos_covid,how = "left",
left_index = True,
right_index = True)
df.head(15)
| provincia | poblacion | area_k2 | geometry | cve | canton | oportunidades | Vivienda | |
|---|---|---|---|---|---|---|---|---|
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Nutrición y Asistencia Médica Básica | 85.280540 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Agua y Saneamiento | 95.038378 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Vivienda | 69.104107 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Seguridad Personal | 87.244399 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Acceso a Conocimientos Básicos | 83.601755 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Acceso a Información y Comunicaciones | 50.593854 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Salud y Bienestar | 70.678446 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Sustentabilidad del Ecosistema | 56.886927 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Derechos Personales | 76.330000 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Libertad Personal y de Elección | 78.121495 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Tolerancia e Inclusión | 78.881617 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Acceso a Educación Superior | 37.934010 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Necesidades Humanas Básicas | 84.166856 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | Fundamentos del Bienestar | 65.440245 |
| ABANGARES | Guanacaste | 19733.0 | 646.178946 | POLYGON ((-84.91642 10.38545, -84.91500 10.384... | 507.0 | ABANGARES | oportunidades | 67.816781 |
df.Vivienda
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
ABANGARES 85.280540
ABANGARES 95.038378
ABANGARES 69.104107
ABANGARES 87.244399
ABANGARES 83.601755
...
ZARCERO 26.500000
ZARCERO 7.142857
ZARCERO 17.326789
ZARCERO 8.399566
ZARCERO 2.007853
Name: Vivienda, Length: 4962, dtype: float64
x = df.centroid.x.mean()
print(x)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:1: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. """Entry point for launching an IPython kernel.
-84.22688272122
y = df.centroid.y.mean()
print(y)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:1: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. """Entry point for launching an IPython kernel.
9.955756377280855
import folium
x = df.centroid.x.mean()
y = df.centroid.y.mean()
m = folium.Map(location=[y, x], zoom_start = 9, tiles = None)
folium.TileLayer('CartoDB positron',control=False).add_to(m)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:3: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. This is separate from the ipykernel package so we can avoid doing imports until C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:4: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. after removing the cwd from sys.path.
<folium.raster_layers.TileLayer at 0x1f0211f5988>
cantones = gp.read_file("geo_data/cantones/cantones.shp")
cantones.head()
cantones = cantones[cantones.provincia == "Cartago"]
cantones.head(5)
| provincia | canton | poblacion | area_k2 | geometry | |
|---|---|---|---|---|---|
| 18 | Cartago | El Guarco | 45548.0 | 171.573039 | POLYGON ((-83.93649 9.85420, -83.92932 9.85254... |
| 19 | Cartago | Cartago | 161727.0 | 278.997036 | POLYGON ((-83.86737 9.97095, -83.86892 9.96971... |
| 21 | Cartago | Paraíso | 62007.0 | 477.139035 | POLYGON ((-83.77791 9.89517, -83.77752 9.89362... |
| 22 | Cartago | Jiménez | 16255.0 | 250.075984 | POLYGON ((-83.76414 9.94766, -83.75970 9.94653... |
| 23 | Cartago | Turrialba | 73616.0 | 1589.335834 | POLYGON ((-83.81609 10.08361, -83.72326 10.039... |
cantones = cantones.set_index('canton')
cantones.head(10)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
| provincia | poblacion | area_k2 | geometry | |
|---|---|---|---|---|
| canton | ||||
| El Guarco | Cartago | 45548.0 | 171.573039 | POLYGON ((-83.93649 9.85420, -83.92932 9.85254... |
| Cartago | Cartago | 161727.0 | 278.997036 | POLYGON ((-83.86737 9.97095, -83.86892 9.96971... |
| Paraíso | Cartago | 62007.0 | 477.139035 | POLYGON ((-83.77791 9.89517, -83.77752 9.89362... |
| Jiménez | Cartago | 16255.0 | 250.075984 | POLYGON ((-83.76414 9.94766, -83.75970 9.94653... |
| Turrialba | Cartago | 73616.0 | 1589.335834 | POLYGON ((-83.81609 10.08361, -83.72326 10.039... |
| Oreamuno | Cartago | 49229.0 | 202.971856 | POLYGON ((-83.94739 10.14751, -83.81563 10.083... |
| La Unión | Cartago | 110194.0 | 44.184626 | POLYGON ((-84.03564 9.88764, -84.03731 9.88878... |
| Alvarado | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... |
cantones.index = [arreglar_cantones(x) for x in cantones.index]
cantones.head()
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
| provincia | poblacion | area_k2 | geometry | |
|---|---|---|---|---|
| EL GUARCO | Cartago | 45548.0 | 171.573039 | POLYGON ((-83.93649 9.85420, -83.92932 9.85254... |
| CARTAGO | Cartago | 161727.0 | 278.997036 | POLYGON ((-83.86737 9.97095, -83.86892 9.96971... |
| PARAISO | Cartago | 62007.0 | 477.139035 | POLYGON ((-83.77791 9.89517, -83.77752 9.89362... |
| JIMENEZ | Cartago | 16255.0 | 250.075984 | POLYGON ((-83.76414 9.94766, -83.75970 9.94653... |
| TURRIALBA | Cartago | 73616.0 | 1589.335834 | POLYGON ((-83.81609 10.08361, -83.72326 10.039... |
datos_covid.index = [arreglar_cantones(x) for x in datos_covid.canton]
datos_covid.head()
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
| cve | canton | oportunidades | Vivienda | |
|---|---|---|---|---|
| SAN JOSE | 101 | SAN JOSE | Nutrición y Asistencia Médica Básica | 82.987394 |
| ESCAZU | 102 | ESCAZU | Nutrición y Asistencia Médica Básica | 85.931253 |
| DESAMPARADOS | 103 | DESAMPARADOS | Nutrición y Asistencia Médica Básica | 88.541844 |
| PURISCAL | 104 | PURISCAL | Nutrición y Asistencia Médica Básica | 90.993459 |
| TARRAZU | 105 | TARRAZU | Nutrición y Asistencia Médica Básica | 91.495155 |
set(cantones.index) - set(datos_covid.index)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code)
set()
df = cantones.merge(datos_covid,how = "left",
left_index = True,
right_index = True)
df.head(15)
| provincia | poblacion | area_k2 | geometry | cve | canton | oportunidades | Vivienda | |
|---|---|---|---|---|---|---|---|---|
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Nutrición y Asistencia Médica Básica | 92.760577 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Agua y Saneamiento | 97.978736 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Vivienda | 89.356684 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Seguridad Personal | 69.972781 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Acceso a Conocimientos Básicos | 88.816013 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Acceso a Información y Comunicaciones | 54.923713 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Salud y Bienestar | 80.897354 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Sustentabilidad del Ecosistema | 67.803337 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Derechos Personales | 79.770000 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Libertad Personal y de Elección | 79.237891 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Tolerancia e Inclusión | 79.774300 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Acceso a Educación Superior | 36.487360 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Necesidades Humanas Básicas | 87.517195 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | Fundamentos del Bienestar | 73.110104 |
| ALVARADO | Cartago | 15219.0 | 79.140674 | POLYGON ((-83.81336 10.01513, -83.81288 10.014... | 306 | ALVARADO | oportunidades | 68.817388 |
x = df.centroid.x.mean()
print(x)
-83.81587522794443
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code) C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:1: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. """Entry point for launching an IPython kernel.
y = df.centroid.y.mean()
print(y)
9.845582134363136
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:1: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. """Entry point for launching an IPython kernel.
import folium
x = df.centroid.x.mean()
y = df.centroid.y.mean()
m = folium.Map(location=[y, x], zoom_start = 9, tiles = None)
folium.TileLayer('CartoDB positron',control=False).add_to(m)
C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:3: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. This is separate from the ipykernel package so we can avoid doing imports until C:\Users\rzamoram\AppData\Local\Continuum\anaconda3\envs\py37ox\lib\site-packages\ipykernel_launcher.py:4: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. after removing the cwd from sys.path.
<folium.raster_layers.TileLayer at 0x1f021967a48>
choropleth = folium.Choropleth(
geo_data = df,
data = df,
columns = ["canton","Vivienda"],
key_on = "feature.properties.canton",
fill_color = 'OrRd',
highlight = True).add_to(m)
m
Se denota visualmente de ambos graficos sobre la provincia de Cartago que a nivel de cantones y de forma visual parece haber una relacion entre Indice de Progreso Social y Vivienda. En general parece que los centros mas urbanos presentan mejores indices de progreso social asi mismo mayor indice de vivienda. El mapeo de estas variables permite de mejor manera en este caso anotar diferencias cantonales.